/*
 * Software for Interactive Project Pool Game
 * Columbia University. New York, 2008
 * Authors:
 *   Abdulhamid Ghandour
 *   Thomas John
 *   Jaime Peretzman
 *   Bharadwaj Vellore
 * 
 * Desc:
 */
#ifndef _BALL_H
#define _BALL_H

#include "types.h"
#include "system.h"
#include "io.h"

bool_t isBallMoving(const struct ball_t *ball);
long long collisionWithTableTime(const struct ball_t *ball, edge_t *edge);
long long collisionWithBallTime(const struct ball_t *ball1, const struct ball_t *ball2);
void handleBallCollision(struct ball_t *ball1, struct ball_t *ball2);
long long handleCollisionWithCue(struct ball_t *ball, const struct ball_t *cue);
void moveBalls(struct ball_t *balls, long long time);
void drawBalls(struct ball_t *balls);
void applyFriction(struct ball_t *balls);

#define BALL_X                         0
#define BALL_Y                         1
#define BALL_COLOUR                    2

#define BALL_0_BASE                    0
#define BALL_1_BASE                    3
#define BALL_2_BASE                    6
#define BALL_3_BASE                    9
#define BALL_4_BASE                   22
#define BALL_5_BASE                   25
#define BALL_6_BASE                   28

#define COL_WHITE                      0
#define COL_YELLOW                     1
#define COL_CYAN                       2
#define COL_INVISIBLE                  3
#define COL_K1                         4
#define COL_K2                         5
#define COL_K3                         6


#define VGA_FLAG                       12

#define SPRITE_X(ball)                 FP2INT((ball).pos.x - (ball).radius)
#define SPRITE_Y(ball)                 FP2INT((ball).pos.y - (ball).radius)

#define IOWR_POS(base,offset,data)     IOWR_16DIRECT(base, (offset) * 2, data)
#define IOWR_VAL(offset,data)          IOWR_POS(VGA_BASE, offset, data)

#endif /* _BALL_H */
